import { Document, Schema, model } from 'mongoose'

export interface IChatMessage extends Document {
  roomId: string
  userId: string
  username: string
  message: string
  timestamp: Date
  isSystem: boolean
}

const ChatMessageSchema = new Schema<IChatMessage>(
  {
    roomId: { type: String, required: true },
    userId: { type: String, required: true },
    username: { type: String, required: true },
    message: { type: String, required: true },
    timestamp: { type: Date, default: Date.now },
    isSystem: { type: Boolean, default: false },
  },
  { versionKey: false }
)

export const ChatMessage = model<IChatMessage>('ChatMessage', ChatMessageSchema)
